import { Component, OnInit } from '@angular/core';
import { MessageService, UserInfoService } from '../../../core/service';
import { StorageService } from 'src/app/core/sotrage/storage.service';
import { MemberService } from '../member.server';
import { ClipboardService } from 'ngx-clipboard';
import { NzMessageService } from 'ng-zorro-antd';
import { Router } from '@angular/router';

@Component({
  selector: 'app-member-center-home',
  templateUrl: './member-center-home.component.html',
  styleUrls: ['./member-center-home.component.scss']
})
export class MemberCenterHomeComponent implements OnInit {
  url = 'center/home';

  imgUrl:string ='../../../../assets/img/tx.jpg';
  private _user:any = {
    coin:{
      coinName:'',
      availableBalance:''
    }
  };
  private _coin:any;
  private _notices:any;
  private _isShowCoin:boolean = false;
  
  ngOnInit() {
    this.msg.sendMessage(this.url);
    this.loadList('首页');
    this.loadList('个人中心[Web前端专用]');
    this._user = this.userInfoService.getUserInfo();
    for (let i = 0; i < 10; i++) {
      var r= Math.floor(Math.random()*(888-199)+199);
      var g= Math.floor(Math.random()*(1000-88)+88);
      var b= Math.floor(Math.random()*(999-444)+444);
      let c =  ' 2px solid ' +  `rgb(${r},${g},${b})`;
      this._bColor.push(c);
    };
  };
  async loadList(url) {
    let data = await this.memberServer.getAJX(url,{});
    this.memberServer.getApiSuccess(data,false) ? this.successListOk(data.data, url) : '';
  };
  private _isLoderCoin:boolean =false;
  private showNOdata:boolean =false;
  public successListOk(data,url):void{
    switch (url) {
      case '首页':
        this._notices = data.notices;
        console.log(this._notices.length) 
        this._notices.length < 1 ? this.showNOdata = true : this.showNOdata = false;
        this.storageService.set('coin', data.mainCoin);
        // this._user.coin = data.mainCoin;
        this._coin = data.mainCoin;
        this._isLoderCoin=true;
        break;
      case '个人中心[Web前端专用]':
        this._user = data;
        data.image ? this.imgUrl = data.image : this.imgUrl = '../../../../assets/img/tx.jpg';
      break;
    };
  };
  private copy():void{
     this._clipboardService.copyFromContent(this._user.address);
     this.message.info('复制地址成功');
  };
  private _bColor:Array<string>=[];

  onMsgClick(item):void{
    if(item.sendType == 'TRADE_ORDER' ||item.sendType == 'WITHDRAWAL' ||item.sendType == 'DEPOSIT' ||item.sendType == 'WITHDRAWAL_CASH'  ){
      this.router.navigate(['/billing', item.args], {
        queryParams: {
          type: item.sendType,
          back:1
        }
      });
    };
  };


  constructor(
    private router: Router,
    private msg: MessageService,
    private memberServer: MemberService,
    private userInfoService: UserInfoService,
    private storageService: StorageService,
    private _clipboardService: ClipboardService,
    private message: NzMessageService,
    
  ) { };
}
